home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Service / Basissoftware / CDIconKiller 1.4 Folder / sources / TrapAvailable.c < prev    next >
C/C++ Source or Header  |  1995-03-10  |  1KB  |  39 lines

  1. #include    "TrapAvailable.h"
  2.  
  3. /* Code from Apple® converted by Stefan Kurth in super-optimized (!) C */
  4.  
  5. /* InitGraf is always implemented (trap $A86E). If the trap table is big
  6.   enough, trap $AA6E will always point to either Unimplemented or some other
  7.   trap, but will never be the same as InitGraf. Thus, you can check the size
  8.   of the trap table by asking if the address of trap $A86E is the same as
  9.   $AA6E. */
  10.  
  11. #define NumToolboxTraps    ((GetToolTrapAddress(_InitGraf) == GetToolTrapAddress(0xAA6E)) ? 0x0200 : 0x0400)
  12.  
  13. /* Determines the type of a trap based on its trap number. If bit 11 is clear,
  14.   then it is an OS trap. Otherwise, it is a Toolbox trap. */
  15. /* OS traps start with A0, Tool with A8 or AA. */
  16.  
  17. #define GetTrapType(which)    (((which) & 0x0800) ? ToolTrap : OSTrap)
  18. #define IsToolTrap(trap)    ((trap) & 0x0800)
  19.  
  20. /* Check to see if a given trap is implemented. */
  21.  
  22. pascal Boolean TrapAvailable(short theTrap)
  23. {
  24. register UniversalProcPtr    theTrapAddress;
  25. register short    temp;
  26.  
  27. temp = theTrap;
  28. if(IsToolTrap(temp)) {
  29.     temp &= 0x07FF;
  30.     if( temp >= NumToolboxTraps)
  31.         return false;
  32.     theTrapAddress = GetToolTrapAddress(temp);
  33.     }
  34. else
  35.     theTrapAddress = GetOSTrapAddress(temp);
  36. return( GetToolTrapAddress(_Unimplemented) != theTrapAddress);
  37. }
  38.  
  39.